home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS11.ADF / C / DirUtil / dirutil.c < prev    next >
C/C++ Source or Header  |  1986-08-05  |  20KB  |  1,007 lines

  1. #include <exec/types.h>
  2. #include <exec/nodes.h>
  3. #include <exec/lists.h>
  4. #include <exec/ports.h>
  5. #include <exec/devices.h>
  6. #include <exec/exec.h>
  7. #include <intuition/intuition.h>
  8. #include <intuition/intuitionbase.h>
  9. #include <graphics/gfxbase.h>
  10. #include <graphics/gfx.h>
  11. #include <graphics/text.h>
  12. #include <graphics/regions.h>
  13. #include <graphics/copper.h>
  14. #include <graphics/gels.h>
  15. #include <graphics/clip.h>
  16. #include <graphics/view.h>
  17. #include <graphics/rastport.h>
  18. #include <graphics/layers.h>
  19. #include <devices/serial.h>
  20. #include <devices/keymap.h>
  21. #include <hardware/blit.h>
  22. #include <stdio.h>
  23. #include <ctype.h>
  24. #include <libraries/dos.h>
  25. #include <libraries/dosextens.h>
  26.  
  27. extern APTR AllocMem();
  28.  
  29. unsigned int mask = 0;
  30. #define INTUITION 0x00000001
  31. #define GRAPHICS  0x00000002
  32. #define SCREEN    0x00000004
  33. #define WINDOW    0x00000008
  34. #define COLORMAP  0x00000010
  35. #define MATH      0x00000020
  36. #define MATHTRANS 0x00000040
  37.  
  38. #define FBSIZE (sizeof (struct FileInfoBlock))
  39.  
  40. struct IntuitionBase *IntuitionBase;
  41. struct GfxBase *GfxBase;
  42. struct IntuiMessage *message;
  43. struct RastPort *rp;
  44. struct Window *w;
  45.  
  46. #define MAXFNAME 15
  47. #define MAXCHAR 30
  48.  
  49. char File_name[MAXFNAME][MAXCHAR+1];
  50.  
  51. #define CURDIR_GADGET 5
  52.  
  53. #define MAXCD 64
  54. char cd_buf[MAXCD+2];
  55.  
  56. USHORT str_pairs [] = { 0,0,  517,0,  517,9,  0,9,  0,0,};
  57. struct Border str_border =
  58. {
  59.     -1,-1,              /* Leftedge, Topedge */
  60.      1, 0, JAM1,        /* FrontPen, BackPen, Drawmode */
  61.      5,                 /* Number of Pairs */
  62.     (APTR) &str_pairs,      /* XY, Pointer to XY pairs */
  63.     NULL,               /* More borders */
  64. };
  65.  
  66. struct IntuiText Curdir_text = {2,0,JAM2,0,-9,NULL,"CURRENT DIRECTORY",NULL,};
  67.  
  68. struct StringInfo Curdir_str = 
  69. {
  70.     cd_buf,
  71.     NULL,
  72.     0,
  73.     MAXCD,  
  74.     0, 0, 0, 0,
  75.     2,0,
  76.     NULL,
  77.     0,
  78.     NULL,
  79. };
  80.  
  81. struct Gadget Curdir_gad =
  82. {
  83.     NULL,
  84.     21,159,
  85.     516, 9,
  86.     GADGHCOMP, GADGIMMEDIATE | RELVERIFY,
  87.     STRGADGET,
  88.     (APTR) &str_border,
  89.     NULL,
  90.     &Curdir_text,
  91.     0,
  92.     &Curdir_str,
  93.     CURDIR_GADGET,
  94.     NULL,
  95. };
  96.  
  97. char cp_buf[MAXCD+1];
  98.  
  99. #define CPDIR_GADGET 7
  100.  
  101. struct IntuiText Cpdir_text = {2,0,JAM2,0,-9,NULL,"DESTINATION",NULL,};
  102.  
  103. struct StringInfo Cpdir_str = 
  104. {
  105.     cp_buf,
  106.     NULL,
  107.     0,
  108.     MAXCD,  
  109.     0, 0, 0, 0,
  110.     2,0,
  111.     NULL,
  112.     0,
  113.     NULL,
  114. };
  115.  
  116. struct Gadget Cpdir_gad =
  117. {
  118.     &Curdir_gad,
  119.     21,185,
  120.     516, 9,
  121.     GADGHCOMP, GADGIMMEDIATE | RELVERIFY,
  122.     STRGADGET,
  123.     (APTR) &str_border,
  124.     NULL,
  125.     &Cpdir_text,
  126.     0,
  127.     &Cpdir_str,
  128.     CPDIR_GADGET,
  129.     NULL,
  130. };
  131.  
  132. /* SLIDE GADGET DEFINITION */
  133. struct IntuiText slide_text =
  134. {
  135.     2,          /* Front Pen */
  136.     2,          /* Back Pen */
  137.     JAM1,       /* Draw Mode */
  138.     -9,         /* Left Edge */
  139.     2,          /* Top Edge */
  140.     NULL,       /* Font */
  141.     (UBYTE *) "SLIDE GADGET",   /* Actual text */
  142.     NULL,
  143. };
  144. #define SLIDE_GADGET 0
  145.  
  146. struct Image slide_img;
  147. struct PropInfo slide_prop;
  148.  
  149. struct Gadget Slide_gad =
  150. {
  151.     &Cpdir_gad,         /* Next gadget */
  152.     20, 14,             /* Left, Top edge */
  153.     20, (8*MAXFNAME)+4, /* Width Hieght */
  154.     GADGHCOMP,          /* Flags */
  155.     GADGIMMEDIATE       /* More flags */
  156.     | RELVERIFY,
  157.     PROPGADGET,         /* Gadget type */
  158.     (APTR)&slide_img,   /* Border definition */
  159.     NULL,               /* Select render */
  160.     NULL,               /* Gadget text */
  161.     0,                  /* MutualExclude */
  162.     (APTR) &slide_prop, /* Special Info - proportional specification */
  163.     SLIDE_GADGET,
  164.     NULL,
  165. };
  166.  
  167. USHORT Pairs [] = { 0,0,  81,0,  81,10,  0,10,  0,0,};
  168. struct Border but_border =
  169. {
  170.     -1,-1,              /* Leftedge, Topedge */
  171.      1, 0, JAM1,        /* FrontPen, BackPen, Drawmode */
  172.      5,                 /* Number of Pairs */
  173.     (APTR) Pairs,      /* XY, Pointer to XY pairs */
  174.     NULL,               /* More borders */
  175. };
  176.  
  177. /* Button Gadget IDs */
  178. #define ALL_GADGET    10
  179. #define CLEAR_GADGET  11
  180. #define COPY_GADGET   12
  181. #define DELETE_GADGET 13
  182. #define PARENT_GADGET 14
  183.  
  184. #define BUT_FIRST ALL_GADGET
  185. #define BUT_LAST  PARENT_GADGET
  186.  
  187. #define BUTWIDTH 8
  188.  
  189. struct IntuiText But_text[] =
  190. {
  191.     2,0,JAM2,0,0,NULL,"   ALL   ",NULL,
  192.     2,0,JAM2,0,0,NULL,"  CLEAR  ",NULL,
  193.     2,0,JAM2,0,0,NULL,"   COPY  ",NULL,
  194.     2,0,JAM2,0,0,NULL,"  DELETE ",NULL,
  195.     2,0,JAM2,0,0,NULL,"  PARENT ",NULL,
  196. };
  197.  
  198. struct Gadget But_gad[] =
  199. {
  200.     NULL,0,175,80,9,GADGHCOMP,GADGIMMEDIATE | RELVERIFY,BOOLGADGET,
  201.         (APTR)&but_border,NULL,NULL,NULL,NULL,ALL_GADGET,NULL,
  202.     NULL,0,175,80,9,GADGHCOMP,GADGIMMEDIATE | RELVERIFY,BOOLGADGET,
  203.         (APTR)&but_border,NULL,NULL,NULL,NULL,CLEAR_GADGET,NULL,
  204.     NULL,0,175,80,9,GADGHCOMP,GADGIMMEDIATE | RELVERIFY,BOOLGADGET,
  205.         (APTR)&but_border,NULL,NULL,NULL,NULL,COPY_GADGET,NULL,
  206.     NULL,0,175,80,9,GADGHCOMP,GADGIMMEDIATE | RELVERIFY,BOOLGADGET,
  207.         (APTR) &but_border,NULL,NULL,NULL,NULL,DELETE_GADGET,NULL,
  208.     NULL,0,175,80,9,GADGHCOMP,GADGIMMEDIATE | RELVERIFY,BOOLGADGET,
  209.         (APTR) &but_border,NULL,NULL,NULL,NULL,PARENT_GADGET,NULL,
  210. };
  211.  
  212. #define FIRST_GADGET But_gad[4]
  213.  
  214. USHORT Fil_pairs [] = { 40,15,  356,15,  356,138,  40,138, 40,15, };
  215. struct Border Fil_border =
  216. {
  217.     -1,-1,              /* Leftedge, Topedge */
  218.      1, 0, JAM1,        /* FrontPen, BackPen, Drawmode */
  219.      5,                 /* Number of Pairs */
  220.     (APTR) Fil_pairs,  /* XY, Pointer to XY pairs */
  221.     NULL,               /* More borders */
  222. };
  223.  
  224. #define WinIDCMP  CLOSEWINDOW | REFRESHWINDOW | GADGETUP | MOUSEBUTTONS
  225.  
  226. struct NewWindow nw =
  227. {
  228.     0,0,                /* Start position */
  229.     640,200,            /* Width, hieght */
  230.     0,1,                /* Detail, block pens */
  231.     WinIDCMP,            /* IDCMP flags */
  232.     WINDOWDEPTH
  233.     | WINDOWDRAG
  234.     | REPORTMOUSE
  235.     | WINDOWCLOSE
  236.     | ACTIVATE
  237.     | SMART_REFRESH,
  238.     &FIRST_GADGET,      /* First gadget in the list */
  239.     NULL,               /* User checkmark */
  240.     "Directory Utility by Chris Nicotra ",/* Window title */
  241.     NULL,               /* Pointer to the screen */
  242.     NULL,               /* Pointer to superbitmap */
  243.     219, 16, 640, 200,  /* Ignored because not sizeable */
  244.     WBENCHSCREEN,       /* Using the Workbench screen */
  245. };
  246.  
  247.  
  248. /* Dos structures and definitions */
  249. extern struct FileLock *Lock();
  250.  
  251. /* The following structure is used to hold the directory entries */
  252. struct DirTable
  253. {
  254.     char  dt_fname[108];         /* File name */
  255.     short dt_select;             /* Select flag */
  256.     short dt_dir;                /* Directory flag */
  257.     long  dt_size;               /* File size */
  258. };
  259.  
  260. int cmp_dt();
  261.  
  262. #define MAXFILE 300
  263. struct DirTable dirtable[MAXFILE];
  264. int numdir;
  265. int cur_index;
  266. char curdir[121];
  267.  
  268. main()
  269. {
  270.     ULONG MessageClass;
  271.     USHORT code;
  272.     struct Gadget *gad_ptr;
  273.     struct IntuiText *text_ptr;
  274.     int i;
  275.  
  276.     *cp_buf = 0;
  277.  
  278.     slide_prop.Flags = FREEVERT | AUTOKNOB;
  279.     slide_prop.VertBody = 0;
  280.     slide_prop.VertPot = 0x8000;
  281.  
  282.     /* Setup the button gadgets */
  283.     for (i=0;i<(BUT_LAST-BUT_FIRST)+1;i++)
  284.     {
  285.         /* Point to the next gadget */
  286.         gad_ptr = &But_gad[i];
  287.         text_ptr = &But_text[i];
  288.  
  289.         gad_ptr->LeftEdge = ((i%2) * 105) + 400;
  290.         gad_ptr->TopEdge = ((i/2) * 20) + 30;
  291.  
  292.         if (i)
  293.             gad_ptr->NextGadget = &But_gad[i-1];
  294.         else
  295.             gad_ptr->NextGadget = &Slide_gad;
  296.  
  297.         gad_ptr->GadgetText = text_ptr;
  298.  
  299.         text_ptr->LeftEdge = 1;
  300.         text_ptr->TopEdge = 1;
  301.     }
  302.  
  303.     /*********************************************************************
  304.     *
  305.     *    Open the libraries and set each "read" mask bit.
  306.     *
  307.     *********************************************************************/
  308.     if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",0)))
  309.     {
  310.         printf("no graphics library!!!\n");
  311.         close_things();
  312.         exit(1);
  313.     }
  314.  
  315.     mask |= GRAPHICS;
  316.  
  317.     if (!(IntuitionBase = (struct IntuitionBase *)
  318.         OpenLibrary("intuition.library",0)))
  319.     {
  320.         printf("no intuition here!!\n");
  321.         close_things();
  322.         exit(2);
  323.     }
  324.  
  325.     mask |= INTUITION;
  326.  
  327.     /*********************************************************************
  328.     *
  329.     *    Open the window on top of the workbench screen
  330.     *
  331.     *********************************************************************/
  332.     if (!(w = (struct Window *) OpenWindow(&nw) ))
  333.     {
  334.         printf("Could not open the window\n");
  335.         close_things();
  336.         exit(3);
  337.     }
  338.  
  339.     mask |= WINDOW;
  340.  
  341.     /*******************************************************************
  342.     *
  343.     *    Initialization before entering main loop
  344.     *
  345.     ******************************************************************/
  346.     rp = w->RPort;
  347.     DrawBorder(rp,&Fil_border,0,0);
  348.  
  349.     /* Load up the directory */
  350.     getdir();
  351.     new_dir();
  352.  
  353.     RefreshGadgets(&FIRST_GADGET,w,NULL);
  354.  
  355.     /* Main event loop */
  356.     for (;;)
  357.     {
  358.         if (message = (struct IntuiMessage *) GetMsg(w->UserPort))
  359.         {
  360.             MessageClass = message->Class;
  361.             code = message->Code;
  362.             ReplyMsg(message);
  363.             switch (MessageClass)
  364.             {
  365.             case GADGETUP:
  366.             case GADGETDOWN:
  367.                 do_gadgets(message,w);
  368.                 break;
  369.  
  370.             case CLOSEWINDOW:
  371.                 close_things();
  372.                 exit (0);
  373.                 break;
  374.  
  375.             case MOUSEBUTTONS:
  376.                 if (code == SELECTDOWN)
  377.                     sel_file();
  378.                 break;
  379.  
  380.             default:
  381.                 break;
  382.             }
  383.         }
  384.     }
  385. }
  386.  
  387. do_gadgets(mes,win)
  388. struct IntuiMessage *mes;
  389. struct Window *win;
  390. {
  391.     struct Gadget *igad;        /* Ptr to gadget that intuition found */
  392.     int gadgid;                 /* ID Code identifying which gadget */
  393.  
  394.     igad = (struct Gadget *) mes->IAddress;     /* PTR to gadget */
  395.     gadgid = igad->GadgetID;
  396.     switch (gadgid)
  397.     {
  398.     case CURDIR_GADGET:
  399.         offIDCMP();
  400.         nullterm(cd_buf,MAXCD);
  401.         Curdir_str.NumChars = strlen(cd_buf);
  402.         Curdir_str.BufferPos = strlen(cd_buf);
  403.         strcpy(curdir,cd_buf);
  404.         getdir();
  405.         new_dir();
  406.         onIDCMP();
  407.         break;
  408.  
  409.     case CPDIR_GADGET:
  410.         nullterm(cp_buf,MAXCD);
  411.         Curdir_str.NumChars = strlen(cp_buf);
  412.         Curdir_str.BufferPos = strlen(cp_buf);
  413.         break;
  414.  
  415.     case SLIDE_GADGET:
  416.         rdis_files();
  417.         break;
  418.  
  419.     case PARENT_GADGET:
  420.         par_dir();
  421.         break;
  422.  
  423.     case DELETE_GADGET:
  424.         del_files();
  425.         break;
  426.  
  427.     case COPY_GADGET:
  428.         copy_files();
  429.         break;
  430.  
  431.     case CLEAR_GADGET:
  432.         clr_files();
  433.         break;
  434.  
  435.     case ALL_GADGET:
  436.         all_files();
  437.         break;
  438.  
  439.     default:
  440.         break;
  441.     }
  442. }
  443.  
  444. close_things()
  445. {
  446.     if (mask & WINDOW)
  447.         CloseWindow(w);
  448.  
  449.     if (mask & GRAPHICS)
  450.         CloseLibrary(GfxBase);
  451.  
  452.     (void) OpenWorkBench();
  453.  
  454.     if (mask & INTUITION)
  455.         CloseLibrary(IntuitionBase);
  456. }
  457.  
  458. getdir()
  459. {
  460.     struct FileLock *filelock;
  461.     char *pwd();
  462.  
  463.     if (!(*curdir))
  464.         strcpy(curdir,pwd());
  465.  
  466.     Curdir_str.NumChars = strlen(curdir);
  467.     Curdir_str.BufferPos = strlen(curdir);
  468.     strcpy(cd_buf,curdir);
  469.     RefreshGadgets(&Curdir_gad,w,NULL);
  470.  
  471.     numdir = 0;
  472.  
  473.     if (!(filelock = Lock(curdir,ACCESS_READ)))
  474.         return;
  475.  
  476.     rd_files(filelock);
  477.     UnLock(filelock);
  478.  
  479.     return;
  480. }
  481.  
  482. rd_files(fl)
  483. struct FileLock *fl;
  484. {
  485.     struct FileInfoBlock *fb;
  486.  
  487.     numdir = 0;
  488.  
  489.     /* Allocate the file info block */
  490.     fb = AllocMem(FBSIZE,MEMF_CLEAR | MEMF_PUBLIC);
  491.  
  492.     if (!Examine(fl,fb))
  493.     {
  494.         FreeMem(fb,FBSIZE);
  495.         close_things();
  496.         exit();
  497.         return;
  498.     }
  499.  
  500.     /* Loop through each of the files in this directory */
  501.     while (ExNext(fl,fb))
  502.     {
  503.         if (fb->fib_DirEntryType < 0)
  504.             dirtable[numdir].dt_dir = 0;
  505.         else
  506.             dirtable[numdir].dt_dir = -1;
  507.  
  508.         dirtable[numdir].dt_select = 0;
  509.         dirtable[numdir].dt_size = fb->fib_Size;
  510.  
  511.         strcpy(dirtable[numdir++].dt_fname,fb->fib_FileName);
  512.  
  513.         if (numdir == MAXFILE)
  514.             break;
  515.     }
  516.  
  517.     /* Sort the table */
  518.     qsort(dirtable,numdir,(sizeof (struct DirTable)),cmp_dt);
  519.  
  520.     FreeMem(fb,FBSIZE);
  521. }
  522.  
  523.  
  524. rdis_files()
  525. {
  526.     USHORT Vpot;
  527.     int numd;
  528.     int pos;
  529.  
  530.     if (numdir > MAXFNAME)
  531.     {
  532.         Vpot = slide_prop.VertPot;
  533.         Vpot >>= 1;
  534.         Vpot &= 0x7fff;
  535.  
  536.         numd = numdir - MAXFNAME;
  537.  
  538.         pos = ((float) Vpot / (float) 0x7fff) * numd;
  539.  
  540.         cur_index = pos;
  541.  
  542.         dis_files(pos);
  543.     }
  544. }
  545.  
  546.  
  547. /**********************************************************************
  548. *
  549. *    new_dir - New directory
  550. *
  551. *    Purpose: To display a new directory and initialize the slide
  552. *        gadget.
  553. *
  554. *    Parameters: None
  555. *
  556. *    Returns: Nothing
  557. *
  558. **********************************************************************/
  559. new_dir()
  560. {
  561.     USHORT Vbody;
  562.  
  563.     if (numdir <= MAXFNAME)
  564.     {
  565.         Vbody = 0xffff;
  566.     }
  567.     else
  568.     {
  569.         Vbody = ((float) 0x7fff) / (((float) numdir) / ((float) MAXFNAME));
  570.         Vbody <<= 1;
  571.     }
  572.  
  573.     cur_index = 0;
  574.  
  575.     ModifyProp(&Slide_gad,w,NULL,slide_prop.Flags,0,0,0,Vbody);
  576.  
  577.     dis_files(0);
  578. }
  579.  
  580. /**********************************************************************
  581. *
  582. *    dis_files - Display files
  583. *
  584. *    Purpose: To display a page of file names
  585. *
  586. *    Parameters:
  587. *        pos - The position in the file list
  588. *
  589. *    Returns: Nothin
  590. *
  591. **********************************************************************/
  592. dis_files(pos)
  593. int pos;
  594. {
  595.     int i;
  596.  
  597.     for (i=0;i<MAXFNAME;i++)
  598.         dis_name(i+pos,i);
  599. }
  600.  
  601. /***********************************************************************
  602. *
  603. *    dis_name - Display a file name
  604. *
  605. *    Purpose: To display a file name
  606. *
  607. *    Parameters:
  608. *        file - File index (into dirtable) or -1 for blank entry
  609. *        pos - The position in the file list
  610. *    Returns: Nothing
  611. *
  612. **********************************************************************/
  613. dis_name(file,pos)
  614. int file;
  615. int pos;
  616. {
  617.     static char file_name[100];
  618.  
  619.     static struct IntuiText file_text =
  620.     {
  621.         2,0,JAM2,45,15,NULL,(UBYTE *) file_name,NULL
  622.     };
  623.  
  624.     /* Set the top position */
  625.     file_text.TopEdge = (pos*8)+16;
  626.  
  627.     if (file == -1 || file >= numdir)
  628.     {
  629.         sprintf(file_name,"%-38.38s","");
  630.         file_text.FrontPen = 1;
  631.         file_text.BackPen = 0;
  632.     }
  633.     else
  634.     {
  635.         if (dirtable[file].dt_dir)
  636.         {
  637.             sprintf(file_name,"%-30.30s%-8.8s",dirtable[file].dt_fname,"");
  638.  
  639.             if (dirtable[file].dt_select)
  640.             {
  641.                 file_text.FrontPen = 3;
  642.                 file_text.BackPen = 2;
  643.             }
  644.             else
  645.             {
  646.                 file_text.FrontPen = 3;
  647.                 file_text.BackPen = 0;
  648.             }
  649.         }
  650.         else
  651.         {
  652.             sprintf(file_name,"%-30.30s %7ld",dirtable[file].dt_fname,
  653.                 dirtable[file].dt_size);
  654.  
  655.             if (dirtable[file].dt_select)
  656.             {
  657.                 file_text.FrontPen = 1;
  658.                 file_text.BackPen = 2;
  659.             }
  660.             else
  661.             {
  662.                 file_text.FrontPen = 1;
  663.                 file_text.BackPen = 0;
  664.             }
  665.         }
  666.     }
  667.  
  668.     /* Display the text */
  669.     PrintIText(rp,&file_text,0,0);
  670. }
  671.  
  672. /**********************************************************************
  673. *
  674. *    sel_file - Select file
  675. *
  676. *    Purpose: To check if a file has been selected and the select
  677. *        or unselect it
  678. *
  679. *    Parameters: None
  680. *
  681. *    Returns: Nothing
  682. *
  683. **********************************************************************/
  684. sel_file()
  685. {
  686.     int file;
  687.     char *ptr;
  688.  
  689.     if (message->MouseX < 45 || message->MouseX > 351)
  690.         return;
  691.  
  692.     if (message->MouseY < 16 || message->MouseY >= (MAXFNAME*8+16))
  693.         return;
  694.  
  695.     file = message->MouseY - 16;
  696.     file /= 8;
  697.  
  698.     if (file > MAXFNAME)
  699.         return;
  700.  
  701.     if ((file+cur_index) > numdir)
  702.         return;
  703.  
  704.     if (dirtable[file+cur_index].dt_dir)
  705.     {
  706.         ptr = curdir + strlen(curdir) - 1;
  707.  
  708.         sprintf(curdir,"%s%s%s",curdir,((*ptr == ':') ? "":"/"),
  709.             dirtable[file+cur_index].dt_fname);
  710.         getdir();
  711.         new_dir();
  712.     }
  713.     else
  714.     {
  715.         dirtable[file+cur_index].dt_select += 1;
  716.         dirtable[file+cur_index].dt_select *= -1;
  717.  
  718.         dis_name(file+cur_index,file);
  719.     }
  720. }
  721.  
  722. /**********************************************************************
  723. *
  724. *    The following routines are called for each of the different
  725. *    types of commands:
  726. *
  727. **********************************************************************/
  728.  
  729. clr_files()
  730. {
  731.     int i;
  732.  
  733.     for (i=0;i<numdir;i++)
  734.         dirtable[i].dt_select = 0;
  735.  
  736.     dis_files(cur_index);
  737. }
  738.  
  739. all_files()
  740. {
  741.     int i;
  742.  
  743.     for (i=0;i<numdir;i++)
  744.         if (!dirtable[i].dt_dir)
  745.             dirtable[i].dt_select = -1;
  746.  
  747.     dis_files(cur_index);
  748. }
  749.  
  750. del_files()
  751. {
  752.     int i;
  753.     char filename[300];
  754.     char *ptr;
  755.     int j;
  756.  
  757.     offIDCMP();
  758.  
  759.     for (j=i=0;i<numdir;i++)
  760.     {
  761.         if (dirtable[i].dt_select)
  762.         {
  763.             ptr = curdir + strlen(curdir)-1;
  764.  
  765.             if (*ptr == ':')
  766.                 sprintf(filename,"%s%s",curdir,dirtable[i].dt_fname);
  767.             else
  768.                 sprintf(filename,"%s/%s",curdir,dirtable[i].dt_fname);
  769.             unlink(filename);
  770.             j++;
  771.         }
  772.     }
  773.  
  774.     if (j)
  775.     {
  776.         getdir();
  777.         new_dir();
  778.     }
  779.  
  780.     onIDCMP();
  781. }
  782.  
  783. copy_files()
  784. {
  785.     int i;
  786.     char filename[300];
  787.     char *ptr;
  788.  
  789.     offIDCMP();
  790.  
  791.     for (i=0;i<numdir;i++)
  792.     {
  793.         if (dirtable[i].dt_select)
  794.         {
  795.             ptr = curdir + strlen(curdir)-1;
  796.  
  797.             if (*ptr == ':')
  798.                 sprintf(filename,"%s%s",curdir,dirtable[i].dt_fname);
  799.             else
  800.                 sprintf(filename,"%s/%s",curdir,dirtable[i].dt_fname);
  801.             copy(filename,cp_buf);
  802.         }
  803.     }
  804.  
  805.     getdir();
  806.     new_dir();
  807.  
  808.     onIDCMP();
  809. }
  810.  
  811. par_dir()
  812. {
  813.     char *ptr;
  814.  
  815.     ptr = curdir+strlen(curdir)-1;
  816.     if (*ptr == ':')
  817.         return;
  818.  
  819.     offIDCMP();
  820.  
  821.     for (ptr = curdir+strlen(curdir)-1;ptr > curdir;ptr--)
  822.     {
  823.         if (*ptr == '/')
  824.         {
  825.             *ptr = 0;
  826.             break;
  827.         }
  828.     }
  829.  
  830.     if (ptr == curdir)
  831.     {
  832.         for (ptr=curdir;*ptr;ptr++)
  833.         {
  834.             if (*ptr == ':')
  835.             {
  836.                 *(ptr+1) = 0;
  837.                 break;
  838.             }
  839.         }
  840.     }
  841.  
  842.     getdir();
  843.     new_dir();
  844.  
  845.     onIDCMP();
  846.     return;
  847. }
  848.  
  849. /* The following function is used to compare two directory entries */
  850. cmp_dt(dt1,dt2)
  851. struct DirTable *dt1,*dt2;
  852. {
  853.    register char *ptr1,*ptr2;
  854.    register c1,c2;
  855.  
  856.    for (ptr1=dt1->dt_fname,ptr2=dt2->dt_fname;*ptr1 && *ptr2;ptr1++,ptr2++)
  857.    {
  858.        c1 = *ptr1;
  859.        c2 = *ptr2;
  860.  
  861.        if (c1 >= 'A' && c1 <= 'Z')
  862.        {
  863.            c1 -= 'A';
  864.            c1 += 'a';
  865.        }
  866.  
  867.        if (c2 >= 'A' && c2 <= 'Z')
  868.        {
  869.            c2 -= 'A';
  870.            c2 += 'a';
  871.        }
  872.  
  873.        if (c1 > c2)
  874.            return (-1);
  875.  
  876.        if (c1 < c2)
  877.            return (1);
  878.    }
  879.  
  880.    if (*ptr1)
  881.        return (-1);
  882.  
  883.    if (*ptr2)
  884.        return (1);
  885.  
  886.    return (0);
  887. }
  888.  
  889.  
  890. onIDCMP()
  891. {
  892.     ModifyIDCMP(w,WinIDCMP);
  893. }
  894.  
  895. offIDCMP()
  896. {
  897.     ModifyIDCMP(w,0);
  898. }
  899.  
  900. copy(s,pc)
  901. char *s;
  902. char *pc;
  903. {
  904.     struct FileHandle  *copyin;
  905.     struct FileHandle  *copyout;
  906.     int iosize;
  907.     int actual;
  908.     char *copybuf;
  909.     char work[300];
  910.     struct FileLock *fl;
  911.     char *ptr;
  912.     char *ptr1;
  913.  
  914.     if (!(copyin = Open(s,MODE_OLDFILE)))
  915.         return;
  916.  
  917.     if ((fl = Lock(pc,ACCESS_READ)))
  918.     {
  919.         UnLock(fl);
  920.  
  921.         ptr = strlen(pc) + pc - 1;
  922.  
  923.         for (ptr1=s+strlen(s)-1;ptr1 > s;ptr1--)
  924.         {
  925.             if (*ptr1 == '/' || *ptr1 == ':')
  926.                 break;
  927.         }
  928.  
  929.         if (*ptr1 == '/' || *ptr1 == ':')
  930.             ptr1++;
  931.  
  932.         if (*ptr == ':')
  933.             sprintf(work,"%s%s",pc,ptr1);
  934.         else
  935.             sprintf(work,"%s/%s",pc,ptr1);
  936.     }
  937.     else
  938.     {
  939.         Close(copyin);
  940.         return;
  941.     }
  942.  
  943.     if (!strcmp(work,s))
  944.     {
  945.         Close(copyin);
  946.         return;
  947.     }
  948.  
  949.     if (!(copyout = Open(work, MODE_NEWFILE)))
  950.     {
  951.          Close(copyin);
  952.          return;
  953.     }
  954.     else
  955.     {
  956.         /* Determine the length of the file */
  957.         iosize = Seek(copyin, 0, OFFSET_END);
  958.         iosize = Seek(copyin, 0, OFFSET_BEGINING);
  959.  
  960.         /* Allocate memory for the copy buffer */
  961.         do
  962.         {
  963.            copybuf = AllocMem(iosize, MEMF_PUBLIC|MEMF_CLEAR);
  964.  
  965.            if (copybuf == 0)
  966.               iosize = iosize/2;
  967.  
  968.         } while (copybuf == 0 & iosize > 512);
  969.  
  970.         /* Copy the file */
  971.         do
  972.         {
  973.            actual = Read(copyin, copybuf, iosize);
  974.  
  975.            if (Write(copyout, copybuf, actual) != actual)
  976.               break;
  977.  
  978.         } while (actual == iosize);
  979.  
  980.         /* Free the copy buffer */
  981.         FreeMem(copybuf, iosize);
  982.  
  983.         /* Close the input and output buffers */
  984.         Close(copyout);
  985.         Close(copyin);
  986.     }
  987. }
  988.  
  989. nullterm(str,len)
  990. char *str;
  991. int len;
  992. {
  993.     int i;
  994.  
  995.     str[len] = 0;
  996.  
  997.     for (i=len;len >= 0;len--)
  998.     {
  999.         if (str[i] != ' ' && str[i])
  1000.             break;
  1001.  
  1002.         str[i] = 0;
  1003.     }
  1004. }
  1005.  
  1006.